package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.WorkflowApplyLine;
import com.hunttown.mes.rpc.domain.WorkflowApplyLineDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-08-01 15:48:24
 */
public class WorkflowApplyLineConverts {

    private static Logger LOG = LoggerFactory.getLogger(WorkflowApplyLineConverts.class);

    public static List<WorkflowApplyLineDTO> convert(List<WorkflowApplyLine> workflowApplyLineList) {
        if (CollectionUtils.isEmpty(workflowApplyLineList)) {
            return Collections.EMPTY_LIST;
        }

        List<WorkflowApplyLineDTO> workflowApplyLineListResult = Lists.newArrayList();
        for (WorkflowApplyLine workflowApplyLine : workflowApplyLineList) {
            workflowApplyLineListResult.add(convert(workflowApplyLine));
        }
        return workflowApplyLineListResult;
    }

    public static WorkflowApplyLineDTO convert(WorkflowApplyLine workflowApplyLine) {
        try {
            return BeanUtils.copy(workflowApplyLine, WorkflowApplyLineDTO.class);
        } catch (Exception e) {
            LOG.error("WorkflowApplyLine到WorkflowApplyLineDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowApplyLine到WorkflowApplyLineDTO转换失败", e);
        }
    }

    public static WorkflowApplyLine convert(WorkflowApplyLineDTO workflowApplyLineDTO) {
        try {
            return BeanUtils.copy(workflowApplyLineDTO, WorkflowApplyLine.class);
        } catch (Exception e) {
            LOG.error("WorkflowApplyLineDTO到WorkflowApplyLine转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowApplyLineDTO到WorkflowApplyLine转换失败", e);
        }
    }
}